lib: Add more filename validations (no ., .. or /) in commit logic
authorColin Walters <walters@verbum.org>
Thu, 5 May 2016 21:20:04 +0000 (17:20 -0400)
committerColin Walters (automation) <walters+githubbot@verbum.org>
Fri, 6 May 2016 01:15:19 +0000 (01:15 +0000)
The filesystem commit code will never give us potentially hostile
filenames, and when importing from archives, we do some validation.

However, we should be extra paranoid and also add error messages in
the mtree in case someone tries to import a hostile
libarchive-supported format.

Closes: #283
Approved by: jlebon

src/libostree/ostree-mutable-tree.c
src/libostree/ostree-repo-commit.c

index bc4f4250f792fb87d6049dd6f5b060155b340732..d0f21f3735b97dc0a6dffeb8510e8254f94d24bc 100644 (file)
@@ -159,6 +159,11 @@ ostree_mutable_tree_replace_file (OstreeMutableTree *self,
 {
   gboolean ret = FALSE;
 
+  g_return_val_if_fail (name != NULL, FALSE);
+
+  if (!ot_util_filename_validate (name, error))
+    goto out;
+
   if (g_hash_table_lookup (self->subdirs, name))
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
@@ -187,6 +192,9 @@ ostree_mutable_tree_ensure_dir (OstreeMutableTree *self,
 
   g_return_val_if_fail (name != NULL, FALSE);
 
+  if (!ot_util_filename_validate (name, error))
+    goto out;
+
   if (g_hash_table_lookup (self->files, name))
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
index 60eb6260ac7ca2e7a51585e3a71e521d811764c2..19040a4535707c2a3be461672cff700bb0a00af9 100644 (file)
@@ -2225,6 +2225,10 @@ create_tree_variant_from_hashes (GHashTable            *file_checksums,
   while (g_hash_table_iter_next (&hash_iter, &key, &value))
     {
       const char *name = key;
+
+      /* Should have been validated earlier, but be paranoid */
+      g_assert (ot_util_filename_validate (name, NULL));
+
       sorted_filenames = g_slist_prepend (sorted_filenames, (char*)name);
     }